<template>
  <el-dialog title="添加员工" width="40%" :before-close="dialogClose" :visible.sync="show">
    <el-form ref="form" label-width="80px">
        <el-form-item label="员工姓名">
          <el-input v-model="form.username" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="员工角色">
          <el-select v-model="form.role" placeholder="请选择员工角色">
            <el-option v-for="(item,index) in roleArr" :key="index" :label="item.role" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="登录密码">
          <el-input type="password" v-model="form.password" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input type="password" v-model="repass" class="select_input"></el-input>
        </el-form-item>
        <div align="center">
          <el-button type="primary" @click="add">确定添加</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </div>
        </el-form-item>
      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: 'staffAdd',
  props:['show','roleArr'],
  data() {
    return {
      form:{
        role:2
      },
      repass:''
    }
  },
  created: function() {
    
  },
  methods: {
    dialogClose:function(){
      this.$emit("func",{'key':'addShow'})
    },
    add:function(){
      if(!this.form.username){
        this.$message.error('请输入用户名');
        return;
      }
      if(!this.form.password){
        this.$message.error('请输入用户密码');
        return;
      }
      if(this.repass !== this.form.password){
        this.$message.error('两次密码输入不一致');
        return;
      }
      this.form.store_id = localStorage.getItem('store_id')
      var that = this
      this.$post('staff/add',this.form).then((res) => {
          if(res.code == 1){
            that.$message.success(res.msg);
            that.$emit("func",{'key':'addShow','type':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>